class Solution {
public:
    int subarraySum(vector<int>& nums, int k) {
        map<int,int> mp;
        mp.insert({0,1});
        int sum = 0;
        int ret = 0;
        for(int num : nums){
            sum += num;
            if(mp.count(sum - k)){
                ret += mp[sum - k];
            }
            mp[sum]++;
        }
        return ret;
    }
};
